<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="949.54">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #0000ff}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0000bf}
p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #007300}
span.s1 {font: 18.0px Helvetica}
span.s2 {text-decoration: underline ; color: #0022f8}
span.s3 {text-decoration: underline ; color: #0000ff}
span.s4 {color: #000000}
span.s5 {text-decoration: underline}
span.s6 {color: #0000bf}
span.s7 {color: #bf0000}
span.s8 {color: #007300}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><span class="s1"><b>MZPokey</b></span><b><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>POKEY Chip Sound Simulator</b></p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p1">Emulation of the sound generation hardware of the POKEY chip by Michael Borisov</p>
<p class="p1">this version calculates in 16bits, is bandlimited and generally better sounding.<span class="Apple-converted-space">  </span>see [<a href="../Pokey/Pokey.html"><span class="s2">Pokey</span></a>] for another more rough 8bit version.</p>
<p class="p2"><br></p>
<p class="p1"><b><span class="Apple-tab-span">	</span>*ar(audf1, audc1, audf2, audc2, audf3, audc3, audf4, audc4, audctl)</b></p>
<p class="p2"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>audfX -</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>7-0 - frequency</p>
<p class="p2"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>audcX -</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>7 - poly5 or direct clock</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>6 - poly4 or poly17</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>5 - poly4/17 or pure tone</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>4 - volume output only</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>3-0 - volume</p>
<p class="p2"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>audctl -</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>7 - switches main clock base from 64KHz to 15KHz</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>6 - inserts high-pass filter into channel 2, clocked by channel 4</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>5 - inserts high-pass filter into channel 1, clocked by channel 3</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>4 - joins channel 4 to channel 3 (16bit resolution)</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>3 - joins channel 2 to channel 1 (16bit resolution)</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>2 - clocks channel 3 with 1.79MHz</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>1 - clocks channel 1 with 1.79MHz</p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>0 - makes the 17bit poly-counter into a 9bit poly-counter</p>
<p class="p2"><br></p>
<p class="p1">code adapted from the MZPOKEY sound chip emulation, v1.6, from the Atari800 emulator project, available here <span class="s3">http://atari800.sourceforge.net/</span></p>
<p class="p3"><span class="s4">more info on how to program this chip can be found here </span><span class="s5">http://www.atariarchives.org/dere/chapt07.php</span><span class="s4"> and here </span><span class="s5">http://www.retroclinic.com/leopardcats/bbpokey/pokey.pdf</span></p>
<p class="p4"><br></p>
<p class="p4"><br></p>
<p class="p5">s.boot;</p>
<p class="p6"><br></p>
<p class="p5">{<span class="s6">MZPokey</span>.ar(<span class="s6">Line</span>.kr(0, 255, 5), 2r00001111)}.play</p>
<p class="p7"><span class="s4">{</span><span class="s6">MZPokey</span><span class="s4">.ar(</span><span class="s6">Line</span><span class="s4">.kr(0, 255, 5), 2r00101111)}.play<span class="Apple-tab-span">	</span></span>//one bit differs in the voice control register</p>
<p class="p7"><span class="s4">{</span><span class="s6">MZPokey</span><span class="s4">.ar(</span><span class="s6">Line</span><span class="s4">.kr(0, 255, 5), 2r10101111)}.play<span class="Apple-tab-span">	</span></span>//one bit differs in the voice control register</p>
<p class="p5">{<span class="s6">MZPokey</span>.ar(<span class="s6">Line</span>.kr(0, 255, 5), 2r10101111, audctl: 2r00000001)}.play<span class="Apple-tab-span">	</span><span class="s7">//another clock</span></p>
<p class="p5">{<span class="s6">MZPokey</span>.ar(<span class="s6">Line</span>.kr(0, 255, 5), 2r10101111, audctl: 2r01000001)}.play<span class="Apple-tab-span">	</span><span class="s7">//with highpass filter</span></p>
<p class="p6"><br></p>
<p class="p7">//--two voices</p>
<p class="p5">{<span class="s6">MZPokey</span>.ar(<span class="s6">MouseX</span>.kr(0, 255), 2r10101010, <span class="s6">MouseY</span>.kr(0, 255), 2r10101010, audctl: 2r00000001)}.play</p>
<p class="p6"><br></p>
<p class="p7">//--all four voices</p>
<p class="p8"><span class="s4">({</span>MZPokey<span class="s4">.ar(</span></p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s6">MouseX</span>.kr(0, 255), 2r11000111,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s6">MouseY</span>.kr(0, 255), 2r11100111,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s6">SinOsc</span>.kr(0.4, 0, 127.5, 127.5), 2r11000111,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s6">SinOsc</span>.kr(0.5, 0, 127.5, 127.5), 2r01000111,</p>
<p class="p7"><span class="s4"><span class="Apple-tab-span">	</span>2r00000000<span class="Apple-tab-span">	</span></span>//general ctl</p>
<p class="p5">).dup}.play)</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p5">(</p>
<p class="p8">SynthDef<span class="s4">(</span><span class="s8">\mzpokey</span><span class="s4">, {</span>|out= 0, gate= 1, f1= 0, c1= 0, f2= 0, c2= 0, f3= 0, c3= 0, f4= 0, c4= 0, ctl= 0, amp= 1, pan= 0|</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s6">var</span> e, z;</p>
<p class="p5"><span class="Apple-tab-span">	</span>e= <span class="s6">EnvGen</span>.kr(<span class="s6">Env</span>.asr(0.01, amp, 0.05), gate, doneAction:2);</p>
<p class="p5"><span class="Apple-tab-span">	</span>z= <span class="s6">MZPokey</span>.ar(f1, c1, f2, c2, f3, c3, f4, c4, ctl);</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s6">Out</span>.ar(out, <span class="s6">Pan2</span>.ar(z*e, pan));</p>
<p class="p5">}).add;</p>
<p class="p5">)</p>
<p class="p6"><br></p>
<p class="p5">(</p>
<p class="p8">Pbind<span class="s4">(</span></p>
<p class="p9"><span class="s4"><span class="Apple-tab-span">	</span></span>\instrument<span class="s4">, </span>\mzpokey<span class="s4">,</span></p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\dur</span>, <span class="s6">Pseq</span>([<span class="s6">Pn</span>(0.1, 10), <span class="s6">Pn</span>(0.05, 12)], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\amp</span>, 0.8,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\ctl</span>, 2r10000000,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\f1</span>, <span class="s6">Pseq</span>([<span class="s6">Pseries</span>(0, 10, 20), <span class="s6">Pgeom</span>(200, 0.94, 20)], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\c1</span>, 2r10101111</p>
<p class="p5">).play</p>
<p class="p5">)</p>
<p class="p6"><br></p>
<p class="p5">(</p>
<p class="p8">Pbind<span class="s4">(</span></p>
<p class="p9"><span class="s4"><span class="Apple-tab-span">	</span></span>\instrument<span class="s4">, </span>\mzpokey<span class="s4">,</span></p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\dur</span>, <span class="s6">Pseq</span>([0.1, 0.08], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\amp</span>, 0.8,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\ctl</span>, <span class="s6">Pseq</span>([<span class="s6">Pn</span>(2r10000000, 48), <span class="s6">Pn</span>(2r01010001, 24)], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\f1</span>, <span class="s6">Pbrown</span>(30, 40, 8)+<span class="s6">Pseq</span>([0, 22], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\c1</span>, <span class="s6">Pseq</span>([2r10101100, 2r11000100, 2r00000000, 2r11100111], <span class="s6">inf</span>)</p>
<p class="p5">).play</p>
<p class="p5">)</p>
<p class="p6"><br></p>
<p class="p5">(</p>
<p class="p8">Pbind<span class="s4">(</span></p>
<p class="p9"><span class="s4"><span class="Apple-tab-span">	</span></span>\instrument<span class="s4">, </span>\mzpokey<span class="s4">,</span></p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\dur</span>, 0.125,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\amp</span>, 0.8,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\ctl</span>, <span class="s6">Pseq</span>([2r10000001, 2r01000001, 2r00100000], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\f1</span>, <span class="s6">Pseq</span>([<span class="s6">Pn</span>(88, 8), <span class="s6">Pseq</span>([120, 130, 140, 50], 4)], <span class="s6">inf</span>)+<span class="s6">Pseq</span>([<span class="s6">Pn</span>(0, 72), <span class="s6">Pn</span>(-10, 36)], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\c1</span>, 2r10101111,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\f2</span>, <span class="s6">Pseq</span>([0, 255, 255, 0, 25, 255, 0, 25, <span class="s6">Pn</span>(13, 11)], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\c2</span>, <span class="s6">Pseq</span>([2r10101111, 2r00100111], <span class="s6">inf</span>)</p>
<p class="p5">).play</p>
<p class="p5">)</p>
<p class="p6"><br></p>
<p class="p5">(</p>
<p class="p8">Pbind<span class="s4">(</span></p>
<p class="p9"><span class="s4"><span class="Apple-tab-span">	</span></span>\instrument<span class="s4">, </span>\mzpokey<span class="s4">,</span></p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\dur</span>, 0.1,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\amp</span>, 0.8,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\ctl</span>, <span class="s6">Pseq</span>([2r00000110, (2r00000110).setBit(0), (2r00000110).setBit(3)], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\f1</span>, <span class="s6">Pseq</span>([30, 80, 70, 30, 80, 70, 30], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\c1</span>, <span class="s6">Pseq</span>([2r11101111], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\f2</span>, <span class="s6">Pseq</span>([8, 9, 10, 8], <span class="s6">inf</span>)*<span class="s6">Pseq</span>([<span class="s6">Pn</span>(1, 64), <span class="s6">Pn</span>(3, 32)], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\c2</span>, 2r11101111,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\f3</span>, <span class="s6">Pseq</span>([<span class="s6">Pn</span>(255, 10), <span class="s6">Pn</span>(55, 6)], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\c3</span>, <span class="s6">Pseq</span>([<span class="s6">Pn</span>(2r10101111, 7), 0], <span class="s6">inf</span>)</p>
<p class="p5">).play</p>
<p class="p5">)</p>
<p class="p6"><br></p>
<p class="p5">(</p>
<p class="p8">Pbind<span class="s4">(</span></p>
<p class="p9"><span class="s4"><span class="Apple-tab-span">	</span></span>\instrument<span class="s4">, </span>\mzpokey<span class="s4">,</span></p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\dur</span>, 0.1,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\amp</span>, 0.8,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\legato</span>, 1.25,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\ctl</span>, 2r10000000,</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\f1</span>, <span class="s6">Pseq</span>([5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 140, 6, 5, 6], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\c1</span>, <span class="s6">Pseq</span>([2r10000000], <span class="s6">inf</span>)|<span class="s6">Pseq</span>([15, 15, 0, 0, 15, 0, 15, 0, 8, 8, 0, 0, 8, 0, 0, 15+64], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\f2</span>, <span class="s6">Pseq</span>([<span class="s6">Pn</span>(0, 32), <span class="s6">Pn</span>(255, 64), <span class="s6">Pseq</span>([0, 255, 255, 0, 25, 255, 0, 25, <span class="s6">Pseries</span>(8, -1, 8)], <span class="s6">inf</span>)]),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\c2</span>, <span class="s6">Pseq</span>([<span class="s6">Pseq</span>([2r10101111, 2r10101000], <span class="s6">inf</span>)], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\f3</span>, <span class="s6">Pseq</span>([<span class="s6">Pn</span>(32, 15), <span class="s6">Prand</span>([33, 35])], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\c3</span>, <span class="s6">Pseq</span>([<span class="s6">Pn</span>(0, 64), <span class="s6">Pn</span>(2r01101000, 32), <span class="s6">Pn</span>(2r11101100, 32)], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\f4</span>, <span class="s6">Pseq</span>([0, 0, 100, 155], <span class="s6">inf</span>),</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s8">\c4</span>, <span class="s6">Pseq</span>([<span class="s6">Pn</span>(0, 128), <span class="s6">Pseq</span>([<span class="s6">Pn</span>(2r11001100, 7), 0], 128)], <span class="s6">inf</span>)</p>
<p class="p5">).play</p>
<p class="p5">)</p>
<p class="p6"><br></p>
<p class="p5">(</p>
<p class="p8">Ptpar<span class="s4">([</span></p>
<p class="p5"><span class="Apple-tab-span">	</span>0, <span class="s6">Pbind</span>(<span class="s8">\instrument</span>, <span class="s8">\mzpokey</span>, <span class="s8">\dur</span>, 0.16, <span class="s8">\amp</span>, 0.2, <span class="s8">\f1</span>, 100, <span class="s8">\c1</span>, 2r01101111),</p>
<p class="p5"><span class="Apple-tab-span">	</span>0.16*16, <span class="s6">Pbind</span>(<span class="s8">\instrument</span>, <span class="s8">\mzpokey</span>, <span class="s8">\dur</span>, 0.181, <span class="s8">\amp</span>, 0.2, <span class="s8">\f2</span>, 10, <span class="s8">\c2</span>, 2r10101111),</p>
<p class="p5"><span class="Apple-tab-span">	</span>0.16*48, <span class="s6">Pbind</span>(<span class="s8">\instrument</span>, <span class="s8">\mzpokey</span>, <span class="s8">\dur</span>, 1.1, <span class="s8">\amp</span>, 0.2, <span class="s8">\legato</span>, 4, <span class="s8">\f2</span>, 20, <span class="s8">\c2</span>, 2r11101111),</p>
<p class="p5"><span class="Apple-tab-span">	</span>0.16*112, <span class="s6">Pbind</span>(<span class="s8">\instrument</span>, <span class="s8">\mzpokey</span>, <span class="s8">\dur</span>, 0.322, <span class="s8">\amp</span>, 0.2, <span class="s8">\legato</span>, 1.8, <span class="s8">\f2</span>, 200, <span class="s8">\c2</span>, 2r11101111),</p>
<p class="p5"><span class="Apple-tab-span">	</span>0.16*200, <span class="s6">Pbind</span>(<span class="s8">\instrument</span>, <span class="s8">\mzpokey</span>, <span class="s8">\dur</span>, 2, <span class="s8">\amp</span>, 0.2, <span class="s8">\legato</span>, 1.8, <span class="s8">\f2</span>, 10, <span class="s8">\c2</span>, 2r11101111)</p>
<p class="p5">]).play</p>
<p class="p5">)</p>
</body>
</html>
